package com.lrkj.property.controller;

import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.core.page.TableDataInfo;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.property.domain.Community;
import com.lrkj.property.service.ICommunityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 小区信息Controller
 *
 * @author yajun_ren
 * @date 2021-07-22
 */
@RestController
@Api(tags = "小区管理")
@RequestMapping("/property/community")
public class CommunityController extends BaseController {
    @Autowired
    private ICommunityService communityService;

    /**
     * 查询小区信息列表
     */
    @ApiOperation(value = "查询小区信息列表", notes = "查询小区信息列表")
    @PreAuthorize("@ss.hasPermi('property:community:list')")
    @GetMapping("/list")
    public TableDataInfo list(Community community) {
        startPage();
        List<Community> list = communityService.selectCommunityList(community);
        return getDataTable(list);
    }

    /**
     * 导出小区信息列表
     */
    @ApiOperation(value = "导出小区信息列表", notes = "导出小区信息列表")
    @PreAuthorize("@ss.hasPermi('property:community:export')")
    @Log(title = "小区信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Community community) {
        List<Community> list = communityService.selectCommunityList(community);
        ExcelUtil<Community> util = new ExcelUtil<Community>(Community.class);
        return util.exportExcel(list, "小区信息数据");
    }

    /**
     * 获取小区信息详细信息
     */
    @ApiOperation(value = "获取小区信息详细信息", notes = "获取小区信息详细信息")
    @PreAuthorize("@ss.hasPermi('property:community:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(communityService.selectCommunityById(id));
    }

    /**
     * 新增小区信息
     */
    @ApiOperation(value = "新增小区信息", notes = "新增小区信息")
    @PreAuthorize("@ss.hasPermi('property:community:add')")
    @Log(title = "小区信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Community community) {
        return toAjax(communityService.insertCommunity(community));
    }

    /**
     * 修改小区信息
     */
    @ApiOperation(value = "修改小区信息", notes = "修改小区信息")
    @PreAuthorize("@ss.hasPermi('property:community:edit')")
    @Log(title = "小区信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Community community) {
        return toAjax(communityService.updateCommunity(community));
    }

    /**
     * 删除小区信息
     */
    @ApiOperation(value = "删除小区信息", notes = "删除小区信息")
    @PreAuthorize("@ss.hasPermi('property:community:remove')")
    @Log(title = "小区信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(communityService.deleteCommunityByIds(ids));
    }

    /**
     * 新增小区信息
     */
    @ApiOperation(value = "设置会计期间", notes = "设置会计期间")
    @PreAuthorize("@ss.hasPermi('property:community:fiscalPeriod')")
    @PostMapping("/fiscalPeriod")
    public AjaxResult fiscalPeriod(@RequestBody Community community) {
        return toAjax(communityService.fiscalPeriod(community));
    }


    /**
     * 获取小区车场信息
     */
    @ApiOperation(value = "获取小区车场信息", notes = "获取小区车场信息")
    @GetMapping(value = "/getCommunityParking/{id}")
    public AjaxResult getCommunityParking(@PathVariable("id") String id) {
        return AjaxResult.success(communityService.getCommunityParking(id));
    }


    /**
     * 获取小区场地信息
     */
    @ApiOperation(value = "获取小区场地信息", notes = "获取小区场地信息")
    @GetMapping(value = "/getCommunitySite/{id}")
    public AjaxResult getCommunitySite(@PathVariable("id") String id) {
        return AjaxResult.success(communityService.getCommunitySite(id));
    }

    /**
     * 获取小区广告位信息
     */
    @ApiOperation(value = "获取小区广告位信息", notes = "获取小区广告位信息")
    @GetMapping(value = "/getCommunityAdvert/{id}")
    public AjaxResult getCommunityAdvert(@PathVariable("id") String id) {
        return AjaxResult.success(communityService.getCommunityAdvert(id));
    }


    /**
     * 初始化账期
     */
    @ApiOperation(value = "初始化账期", notes = "初始化账期")
    @PostMapping("/initFiscalPeriod")
    public AjaxResult initFiscalPeriod(@RequestBody Community community) {
        return toAjax(communityService.initFiscalPeriod(community));
    }


}
